package com.mudingkou.mos.common.pojo.response;


import com.mudingkou.mos.common.Message;
import com.mudingkou.mos.common.enums.CommonResultEnum;

/**
 * <p>基础返回结果</p>
 *
 * @author kzc
 * @date 2020/5/2
 */
public class BaseResponse {

    private boolean success;

    public boolean isSuccess() {
        return success;
    }

    public BaseResponse setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    /**
     * 返回码
     */
    protected int code;
    /**
     * 返回消息
     */
    protected String message;

    protected BaseResponse() {
        // 默认创建成功的回应
        this(CommonResultEnum.SUCCESS,true);
    }
    protected BaseResponse(Message message,boolean success) {
        this(message.getCode(), message.getMessage(),success);
    }

    protected BaseResponse(int code, String message,boolean success) {
        this.code = code;
        this.message = message;
        this.success = success;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static BaseResponse success(){
        return new BaseResponse();
    }

    public static BaseResponse success(int code, String message){
        return new BaseResponse(code,message,true);
    }
    public static BaseResponse success(Message message){
        return new BaseResponse(message,true);
    }



    public static BaseResponse fail(Message message){
        return new BaseResponse(message,false);
    }

    public static BaseResponse fail(int code, String message){
        return new BaseResponse(code,message,false);
    }

    public static BaseResponse fail(){
        return new BaseResponse(CommonResultEnum.ERROR_UNKNOWN,false);
    }
    public static BaseResponse fail(String message){
        BaseResponse baseResponse = new BaseResponse(CommonResultEnum.ERROR_UNKNOWN,false);
        baseResponse.setMessage(message);
        return baseResponse;
    }
}
